package com.godofball.todo.controller;


import com.godofball.todo.entity.Task;
import com.godofball.todo.entity.utils.ResponseResult;
import com.godofball.todo.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 任务表(Task)表控制层
 *
 * @author makejava
 * @since 2023-12-31 16:36:51
 */
@RestController
@RequestMapping("task")
@Slf4j
@CrossOrigin
public class TaskController {

    @Autowired
    private TaskService taskService;

    /**
     * @param pageNum
     * @param pageSize
     * @param title
     * @param type
     * @return
     */
    @GetMapping("workTask")
    public ResponseResult selectWorkTask(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String title,
            String type) {
        return taskService.selectWorkTask(pageNum, pageSize, title, type);
    }

    @GetMapping("doneTask")
    public ResponseResult selectDoneTask(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String title,
            String content,
            String type) {
        return taskService.selectDoneTask(pageNum, pageSize, title, content, type);
    }

    @PostMapping
    public ResponseResult addTask(@RequestBody Task task) {
        log.info(task.toString());
        return taskService.addTask(task);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteTask(@PathVariable("id") String id) {
        return taskService.deleteTask(id);
    }

    @PutMapping
    public ResponseResult updateTask(@RequestBody Task task) {
        return taskService.updateTask(task);
    }

    @PutMapping("/submit/{id}")
    public ResponseResult submitTask(@PathVariable("id") String id) {
        return taskService.submitTask(id);
    }

    @GetMapping("taskNumber")
    public ResponseResult selectTaskNumber() {
        return taskService.selectTaskNumber();
    }

    @GetMapping("taskByTime")
    public ResponseResult selectTaskByTime() {
        return taskService.selectTaskByTime();
    }

    @GetMapping("taskByWeek")
    public ResponseResult selectTaskByWeek(){
        return taskService.selectTaskByWeek();
    }


}

